<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>KIT ADMIN</title>
    <link rel="stylesheet" href="/statics/plugins/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/statics/plugins/font-awesome/css/font-awesome.min.css" media="all"/>
    <link rel="stylesheet" href="/statics/src/css/app.css" media="all"/>
    <link rel="stylesheet" href="/statics/src/css/themes/default.css" media="all" id="skin" kit-skin/>
    <script src="/statics/plugins/layui/layui.js"></script>
</head>
<body>
<div class="x-body">
    <div style="margin-left: 20px">
        <table class="layui-form x-center" action="" style="width:80%">
            <div class="layui-form-pane" style="margin-top: 15px;">
                <div class="layui-form-item">
                    <label class="layui-form-label">服务名</label>
                    <div class="layui-input-inline">
                        <input type="text" id="s_name" placeholder="请输入服务名" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-input-inline" style="width:80px" id="" title="搜索">
                        <button class="layui-btn" id="searchBtn" data-type="reload"><i class="layui-icon">&#xe615;</i>
                        </button>
                    </div>
                    <a class="layui-btn layui-btn-small"
                       style="line-height:1.6em;margin-top:3px;float:right;padding-top: 5px"
                       href="javascript:location.replace(location.href);" title="重置">重置
                    </a>
                </div>
            </div>
        </table>
        <div>
            <button class="layui-btn layui-btn-danger" id="delBtn" data-type="getCheckData">
                <i class="layui-icon">&#xe640;</i>
                批量删除
            </button>
            <button class="layui-btn" onclick="admin_add('添加用户','/item/goAdd','600','500')"><i
                    class="layui-icon">&#xe608;</i>添加
            </button>
            <button class="layui-btn " id="reloadBtn" data-type="reload" title="刷新">
                <i class="layui-icon" style="line-height:30px">ဂ</i>
            </button>
        </div>
    </div>
    <table class="layui-hide" id="adminTable"></table>
    <script type="text/html" id="operateTpl">
        <span class="td-manage">
            <a title="编辑" href="javascript:;" onclick="admin_add('编辑用户','/item/goAdd?id={{d.itemId}}','600','500')"
               class="ml-5" style="text-decoration:none">
                <i class="layui-icon">&#xe642;</i>
            </a>
            <a title="删除" href="javascript:;" onclick="admin_del(this,'{{d.itemId}}')"
               style="text-decoration:none">
                <i class="layui-icon">&#xe640;</i>
            </a>
        </span>
    </script>

</div>

<script>
    layui.use('table', function () {
        var $ = layui.$;
        var table = layui.table, form = layui.form;
        table.render({
            elem: '#adminTable',
            url: '/item/getData',
            cellMinWidth: 80,
            cols: [
                [{
                    checkbox: true,
                    fixed: true
                }, {
                    field: 'itemId',
                    title: '项目编号',
                }, {
                    field: 'itemName',
                    title: '项目名称',
                }, {
                    field: 'itemTime',
                    title: '服务时间',
                }, {
                    field: 'itemPrice',
                    title: '服务费用',
                }, {
                    field: 'itemIntro',
                    title: '项目简介',
                }, {
                    title: '操作',
                    templet: '#operateTpl',
                }]
            ],
            id: 'reloadId',
            page: true
        });
        var active = {
            reload: function () {
                var s_name = $('#s_name');
                table.reload('reloadId', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    },
                    where: {
                        itemName: s_name.val(),
                    }
                });
            },
            getCheckData: function () { //获取选中数据
                var checkStatus = table.checkStatus('reloadId');
                var data = checkStatus.data;
                $.post({
                    dataType: 'json',
                    contentType: 'application/json',
                    url: "/item/deletes",
                    data: JSON.stringify(data),
                    success: function (result) {
                        if (result.code == 0) {
                            layer.msg('已删除!', {icon: 1, time: 1000});
                            table.reload('reloadId');
                        } else {
                            layer.msg(result.result, {icon: 6, time: 1000});
                        }
                    },
                    error: function () {
                        layer.msg('网络繁忙!', {icon: 6, time: 1000});
                    }
                });
            }
        };

        $('#delBtn').on('click', function () {
            var type = $(this).data('type');
            layer.confirm('确认要删除吗？', function (index) {
                active[type] ? active[type].call(this) : '';
                layer.close(index);
            });
        });
        $('#searchBtn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        $('#reloadBtn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });
    //批量删除提交


    /*添加*/
    function admin_add(title, url, w, h) {
        x_admin_show(title, url, w, h);
    }

    function x_admin_show(title, url, w, h) {
        if (title == null || title == '') {
            title = false;
        }
        ;
        if (url == null || url == '') {
            url = "404.html";
        }
        ;
        if (w == null || w == '') {
            w = 800;
        }
        ;
        if (h == null || h == '') {
            h = ($(window).height() - 50);
        }
        ;
        layer.open({
            type: 2,
            area: [w + 'px', h + 'px'],
            fix: false, //不固定
            maxmin: true,
            shadeClose: true,
            shade: 0.4,
            title: title,
            content: url
        });
    }

    /*删除*/
    function admin_del(obj, itemId) {
        layer.confirm('确认要删除吗？',
            function (id) {
                $ = layui.jquery;
                //发异步删除数据
                $.post({
                    url: "/item/delete",
                    data: {id: itemId},
                    success: function (result) {
                        if (result.code == 0) {
                            $(obj).parents("tr").remove();
                            layer.msg('已删除!', {icon: 1, time: 1000});
                        } else {
                            layer.msg(result.result, {icon: 6, time: 1000});
                        }
                    },
                    error: function () {
                        layer.msg('网络繁忙!', {icon: 6, time: 1000});
                    }
                });
            },
            function (index) {

            }
        );
    }


</script>
</body>
</html>